﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;


namespace Mota
{

    public class httpUtil
    {

        public List<WeatherClass> weatherList = new List<WeatherClass>();
        public bool isWeatherGet = false;

        public httpUtil()
        {
            
        }

        public void testRequest(string url)
        {
            WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
            wc.DownloadStringAsync(new Uri(url));
        }

        
        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
 
                DataContractJsonSerializer sir = new DataContractJsonSerializer( typeof(List<WeatherClass>) );
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));

                weatherList = (List<WeatherClass>)sir.ReadObject(ms);
                isWeatherGet = true;
                
                //foreach (var res in weatherList)
                //{
                //    MessageBox.Show(res.station);
                //}
            }
        }
    }
}
